﻿using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;

[TestClass]
public class FileEncryptionTest
{
    private const string INPUT_FILE_NAME = @"..\..\..\FileEncryption\example.bin";

    private static void VerifyData(byte[] actualData, byte[] expectedData)
    {
        Assert.AreEqual(expectedData.Length, actualData.Length);
        for (int i = 0; i < expectedData.Length; i++)
        {
            Assert.AreEqual(expectedData[i], actualData[i]);
        }
    }

    private static byte[] ExtractData()
    {
        byte[] result;
        FileStream file = new FileStream(INPUT_FILE_NAME, FileMode.Open, FileAccess.Read);
        using (file)
        {
            result = new byte[file.Length];
            file.Read(result, 0, result.Length);
        }
        return result;
    }

    public static void CreateFile(byte[] data)
    {
        FileStream inputFile = new FileStream(INPUT_FILE_NAME, FileMode.Create, FileAccess.Write);
        using (inputFile)
        {
            inputFile.Write(data, 0, data.Length);
        }

    }

    [TestMethod]
    public void SampleTest()
    {
        byte[] inputData = { 0xF5, 0xA8, 0x22, 0xC3, 0xFE, 0x34, 0x56, 0x62 };
        CreateFile(inputData);
        FileEncryption.Main();
        byte[] resultingData = ExtractData();
        byte[] expectedData = { 0xFE, 0xF5, 0xA8, 0x22, 0xC3, 0x62, 0x34, 0x56 };
        VerifyData(resultingData, expectedData);

    }

    [TestMethod]
    public void TenByteTest()
    {
        byte[] inputData = { 0xF5, 0xA8, 0x22, 0xC3, 0xFE, 0x34, 0x56, 0x62, 0x11, 0xDE };
        CreateFile(inputData);
        FileEncryption.Main();
        byte[] resultingData = ExtractData();
        byte[] expectedData = { 0xFE, 0xF5, 0xA8, 0x22, 0xC3, 0xDE, 0x34, 0x56, 0x62, 0x11 };
        VerifyData(resultingData, expectedData);
    }

    [TestMethod]
    public void TwoByteTest()
    {
        byte[] inputData = { 0xF5, 0xA8 };
        CreateFile(inputData);
        FileEncryption.Main();
        byte[] resultingData = ExtractData();
        byte[] expectedData = { 0xA8, 0xF5 };
        VerifyData(resultingData, expectedData);
    }
}
